// Created by zyq on 2025/3/26.
#include "iostream"

using namespace std;

class Component {
public:
    virtual void operation() = 0;
};

class ConcreteComponent : public Component {
public:
    void operation() override {
        cout << "ConcreteComponent operation" << endl;
    }
};

class Decorator : public Component {
protected:
    Component *component;
public:
    void setComponent(Component *component) {
        this->component = component;
    }

    void operation() override {
        component->operation();
    }
};

class ConcreteDecoratorA : public Decorator {
private:
    string addState;

public:
    void operation() override {
        Decorator::operation();
        addState = "ConcreteDecoratorA addState";
        cout << addState << endl;
    }
};

class ConcreteDecoratorB : public Decorator {
private:
    string addState;

public:
    void operation() override {
        Decorator::operation();
        addState = "ConcreteDecoratorB addState";
        cout << addState << endl;
    }
};

int main() {
    ConcreteComponent *c = new ConcreteComponent();
    ConcreteDecoratorA *a = new ConcreteDecoratorA();
    ConcreteDecoratorB *b = new ConcreteDecoratorB();
    a->setComponent(c);
    b->setComponent(a);
    b->operation();

    return 0;

}